<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

if ($_REQUEST["HidId"] != "") {
    $tabla = "solotb_nivel1";
    switch ($_REQUEST["opc"]) {
        case ("M"):
            $tipo = "UPDATE";
        //Valida si no se ha modificado nada, regresa con OK
            if ($_REQUEST["TxtDesc"]==$_REQUEST["TxtDesc0"]) {
                header("Location:trn_Empresas.php?MiError=0");
            }

            $strSql="$tipo $tabla set ";
            $strSql .= "des='" . $_REQUEST["TxtDesc"] . "' ";
            $strSql .=  "where id1=" . $_REQUEST["HidId"];

            //ruta=server.MapPath("/documentacion") & "\" & Request("TxtDesc0")

            //Set fso = Server.CreateObject("Scripting.FileSystemObject")
            //Set f = fso.GetFolder(ruta)
            //f.Name=Request("TxtDesc")
            //if err<>0 then
            // response.redirect "trn_empresas.asp?MiError=1&des=" & err.description
            //response.write err & "-" &err.description
            //response.end
            //end if
            break;
        case ("E"):
            $tipo = "DELETE";
            $strSql="$tipo from $tabla where id1=" . $_REQUEST["HidId"];
            //ruta=server.MapPath("/documentacion") & "\" & Request("TxtDesc")

            //Set fs = CreateObject("Scripting.FileSystemObject")
            //fs.DeleteFolder(ruta)
            //if err<>0 then
            // response.redirect "trn_empresas.asp?MiError=1&des=" & err.description
            //response.write err & "-" &err.description
            //response.end
            //end if
            break;
        default:
            $tipo = "INSERT";
            $strSql="$tipo into $tabla values (";
            $strSql .=  $_REQUEST["HidId"] . ",'";
            $strSql .=  $_REQUEST["TxtDesc"] . "')";
            break;
    }

    $arrQueries = array();
    array_push($arrQueries, $strSql);
    array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));
    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);

    //$oConexion->EjecutarQuery($strSql);
    $oConexion->EjecutarTransaccion($arrQueries);
    $oConexion->Cerrar();
    //OJO REVISAR PARA QUE SE REALICE BORRADO EN CASCADA
    //O BIEN BORRAR EN TODAS LAS TABLAS ASOCIADAS
    if ($_REQUEST["opc"]== "E") {
        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);

        //$exito = $oConexion->EjecutarQuery("delete from solotb_nivel2 where id1=" . $_REQUEST["HidId"]);
        $tipo = "DELETE";
        $tabla = "solotb_nivel2";
        $query = "delete from solotb_nivel2 where id1=" . $_REQUEST["HidId"];
        $arrQueries = array();
        array_push($arrQueries, $query);
        array_push($arrQueries, crearQueryLog($tabla, $tipo, $query));
        $oConexion->EjecutarTransaccion($arrQueries);
        $oConexion->Cerrar();
    }

    if (!$exito) {
//'	 response.write STRsqL & err.description
        $strMsg="trn_Empresas.php?MiError=1&des=" . $oConexion->getErrorMessage();
        //echo $strMsg;
    }else {
        $strMsg="trn_Empresas.php?MiError=0";
    }
//  set ObjGraba=nothing
    header ("Location: $strMsg");

}
//'CODIGO CUANDO SE SUBMITE LA PAGINA
switch  ($_REQUEST["opc"]) {
    case ("M"):
        $boton ="<input type='submit' name='CmdGrabar' value='Modificar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='M'>";
        $titulo="Modificaci&oacute;n de Subsecretar&iacute;a";
        break;
    case ("E"):
        $boton ="<input type='submit' name='CmdGrabar' value='Eliminar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='E'>";
        $titulo="Eliminaci&oacute;n de Subsecretar&iacute;a";
//'		  case "C"
//'		       boton ="<input type='button' name='CmdGrabar' value='Regresar' class='boton' Onclick='javascript:history.back();'>"
//'		       titulo="Consulta de Categor�as"
//'              strSql="select * from tb_empresas_categoria where id1=" & Request("id" )& " order by ds_tran"

//'               set Obj=Server.CreateObject("ADODB.Recordset")
//'               Obj.Open strSql,Session("conn")
//'               if err<>0 then
//'                  strERROR=1
//'                  err=0
//'               end if
//'               arrData=Obj.Getrows()
//'               set Obj=Nothing
}
?>

<html>
    <head>
        <title>Documentaci&oacute;n</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
    </head>

    <body topmargin=0 leftmargin=0>
        <p align="center"class="SoloStyle_TituloPaginas"><?php echo $titulo; ?></p>

        <?php if ($_REQUEST["opc"] != "C") { ?>
        <form name="frmIngreso" action="trn_GrabaEmpresa.php" method="POST">
            <table border="0" width="70%" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Id</b></td>
                    <td class="soloStyle_Texto"><?php echo $_REQUEST["id"];?><input type="hidden" maxlenght="50" size="50" name="HidId" class="texto" value="<?php echo $_REQUEST["id"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Subsecretar&iacute;a</b></td>
                    <td><input type="text" maxlenght="50" size="50" name="TxtDesc" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds"];?>"><input type="hidden" maxlenght="50" size="50" name="TxtDesc0" class="SoloStyle_texto" value="<?php $_REQUEST["ds"];?>"></td>
                </tr>
            </table>
            <br><center><?php echo $boton;
    echo $oculto;?></center>
        </form>
        <br>
    <?php } else { ?>
        <table width="75%" border="0" align="center" class="grid">
            <tr class="SoloStyle_Etiqueta">
                <td>Empresa: <?php echo $_REQUEST["ds"];?></td>
            </tr>
    <?php for ($i=0; $i < count($arrData);$i++) {?>
            <tr>
                <td><?php echo $arrData[$i][2];?></td>

            </tr>
        <?php }?>
        </table>
        <br><center><?php echo $boton; ?></center>
    <?php } ?>
    </body>
</html>
